package com.sneakxy.mybase4j.generator.config;

import javax.xml.bind.annotation.XmlAttribute;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.sneakxy.mybase4j.generator.jdbc.Dialect;
import com.sneakxy.mybase4j.generator.jdbc.JdbcHelper;

/**
 * @author 潜行的青衣
 * @see
 */
public class Jdbc {
	
	private static Logger log = LogManager.getLogger(Jdbc.class);

	private String dialect;
	
	private String driver;
	
	private String url;
	
	private String username;
	
	private String password;

	public JdbcHelper createJdbcHelper() {
		return new JdbcHelper(this);
	}
	
	public Dialect createDialect() {
		Object result = null;
		try {
			result = Class.forName(this.dialect).newInstance();
			log.info("dialect create success!");
		} catch (InstantiationException e) {
			log.error("create dialect error!", e);
		} catch (IllegalAccessException e) {
			log.error("create dialect error!", e);
		} catch (ClassNotFoundException e) {
			log.error("create dialect error!", e);
		}
		return (Dialect) result;
	}
	
	@XmlAttribute(name="dialect")
	public String getDialect() {
		return dialect;
	}

	public void setDialect(String dialect) {
		this.dialect = dialect;
	}

	@XmlAttribute(name="driver")
	public String getDriver() {
		return driver;
	}

	public void setDriver(String driver) {
		this.driver = driver;
	}

	@XmlAttribute(name="url")
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@XmlAttribute(name="username")
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@XmlAttribute(name="password")
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
}
